import java.io.File;


public class Failihaldur {

	public static void kustutafail(String failinimi) {
		File f = new File(failinimi);
		if (!f.exists())return; //faili pole, siis pole ju ka vaja midagi üle kirjutada
		if (!f.canWrite())
			throw new IllegalArgumentException("Delete: write protected: " + failinimi);

		// If it is a directory, make sure it is empty
		if (f.isDirectory()) {
			String[] files = f.list();
			if (files.length > 0)
				throw new IllegalArgumentException(
						"Delete: directory not empty: " + failinimi);
		}
		// Attempt to delete it
		boolean success = f.delete();
		if (!success)
			throw new IllegalArgumentException("Delete: deletion failed");
	}
}
